package com.zyw.service.repertory.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zyw.entity.RepertoryMaterialLog;
import com.zyw.from.repertoryFrom;
import com.zyw.mapper.repertory.RepertoryMaterialLogMapper;
import com.zyw.service.repertory.RepertoryMaterialLogService;
import com.zyw.util.UnitConversionUtil;
import com.zyw.vo.LayUITableVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


@Slf4j
@Service
public class RepertoryMaterialLogServiceImpl implements RepertoryMaterialLogService {

    @Resource
    public RepertoryMaterialLogMapper repertoryMaterialLogMapper;


    @Override
    @Transactional
    public void save(RepertoryMaterialLog repertoryMaterialLog) {
        repertoryMaterialLogMapper.insertSelective(repertoryMaterialLog);
    }

    @Override
    public LayUITableVO<List<RepertoryMaterialLog>> findPage(Map<String, Object> map) {
        repertoryFrom from = (repertoryFrom) map.get("from");

        PageHelper.startPage((int) map.get("page"),(int) map.get("limit"));



        List<RepertoryMaterialLog> list = repertoryMaterialLogMapper.findPage(map);
        for (RepertoryMaterialLog repertoryMaterialLog : list) {
            repertoryMaterialLog.setDate(UnitConversionUtil.conversionDate(repertoryMaterialLog.getDate()));
        }

        PageInfo<RepertoryMaterialLog> pageInfo = new PageInfo<>(list);

        LayUITableVO<List<RepertoryMaterialLog>> vo = new LayUITableVO<>();
        vo.setCount(pageInfo.getTotal());
        vo.setData(pageInfo.getList());

        return vo;
    }
}
